package com.googlecode.chigs.web.plugin;

import java.util.Arrays;
import java.util.List;

import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;

import brix.Brix;
import brix.Plugin;
import brix.jcr.api.JcrSession;
import brix.plugin.site.page.tile.Tile;
import brix.registry.ExtensionPointRegistry;
import brix.web.tab.AbstractWorkspaceTab;
import brix.web.tab.IBrixTab;
import brix.workspace.Workspace;

import com.googlecode.chigs.web.StatisticsTile;
import com.googlecode.chigs.web.admin.AdminStatisticsTile;
import com.googlecode.chigs.web.admin.configlocation.ManageLocationsTile;
import com.googlecode.chigs.web.admin.configlocationgroup.ManageLocationGroupsTile;
import com.googlecode.chigs.web.admin.product.ManageProductsTile;
import com.googlecode.chigs.web.admin.variant.ManageVariantsTile;
import com.googlecode.chigs.web.admin.version.ManageVersionsTile;
import com.googlecode.chigs.web.config.configrevision.ManageConfigRevisionsTile;
import com.googlecode.chigs.web.config.configuration.ManageConfigurationsTile;
import com.googlecode.chigs.web.doku.module.ManageModulesTile;
import com.googlecode.chigs.web.doku.revision.ManageRevisionsTile;

public class ChigsPlugin implements Plugin {

    public ChigsPlugin(Brix brix) {
        // Admin
        final ExtensionPointRegistry registry = brix.getConfig().getRegistry();
		registry.register(Tile.POINT, new ManageLocationsTile());
        registry.register(Tile.POINT, new ManageLocationGroupsTile());
        registry.register(Tile.POINT, new AdminStatisticsTile());
        registry.register(Tile.POINT, new ManageProductsTile());
        registry.register(Tile.POINT, new ManageVariantsTile());
        registry.register(Tile.POINT, new ManageVersionsTile());
        
        // Statistics
        registry.register(Tile.POINT, new StatisticsTile());
        
        // Documentation
        registry.register(Tile.POINT, new ManageModulesTile());
        registry.register(Tile.POINT, new ManageRevisionsTile());
        
        // Configuration
        registry.register(Tile.POINT, new ManageConfigurationsTile());
        registry.register(Tile.POINT, new ManageConfigRevisionsTile());
    }
    
    @Override
	public String getId() {
		return getClass().getName();
	}

	@Override
	public String getUserVisibleName(Workspace workspace, boolean isFrontend) {
        return null;
	}

	@Override
	public List<Workspace> getWorkspaces(Workspace currentWorkspace, boolean isFrontend) {
		return null;
	}

	@Override
	public void initWorkspace(Workspace workspace, JcrSession workspaceSession) {
	}

	@Override
	public boolean isPluginWorkspace(Workspace workspace) {
		return false;
	}

	@Override
    public List<IBrixTab> newTabs(IModel<Workspace> workspaceModel) {
        IBrixTab tabs[] = new IBrixTab[]{new Tab(new Model<String>("Chigs"), workspaceModel)};
        return Arrays.asList(tabs);
    }

    static class Tab extends AbstractWorkspaceTab {
        public Tab(IModel<String> title, IModel<Workspace> workspaceModel) {
            super(title, workspaceModel, 99);
        }

        @Override
        public Panel newPanel(String panelId, IModel<Workspace> workspaceModel) {
            return new ChigsPanel(panelId, workspaceModel);
        }
    }
}
